<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/layouts/include/taglib.jsp" %>

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="decorator" content="default" />
	<script type="text/javascript">
        var GOBAL_CUST_ROLENO = '<shiro:principal property="roleNo"/>'; //当前用户角色
        var datatablePrjRecord;
    </script>
</head>
<body>
	<script>
	var datatable;
	var prjName;
	//查询
	function queryPrj() {
		
		var oSettings = datatable.fnSettings();
		oSettings._iDisplayStart = 0;
		datatable.fnClearTable(0); //清空数据
		datatable.fnDraw(); //重新加载数据 
	}
	
	//删除方法 
	function del(id,prjName){
		Otod.Msg.confirm('确定删除此项目【'+prjName+'】?',"删除项目", delOk);
		//删除方法 
		function delOk(){
			Otod.ajax({
			   url: "${ctx}/pm/project/delPrjs.do?projectId=" + id,
				//url:"${ctx}/pm/project/remove.do?projectId=" + id,
			    type: "GET",
			    successFn: function(data) {
			    	queryPrj();
			    }
			});
		}
	}
	
	//日期控制状态显示
	function checkDate(statusName,prjDate){
		var days = DateUtil.dateDiff('d', prjDate, new Date().getTime());//结果为正数（小，大）后面减前面
		if(days>-5&&days<=-3){
			//蓝色预警
			return '<font style="color:blue">'+statusName+'(项目结束时间临近，请督促人员提交项目任务！)'+'</font>';
		}else if(days>-3&&days<=0){
			//黄色警告
			return '<font style="color:yellow">'+statusName+'(项目马上到期,请尽快完成项目)'+'</font>';
		}else if(days>0&&days<=3){
			//红色警告
			return '<font style="color:red">'+statusName+'(项目已超时'+days+'天)'+'</font>';
		}else if(days>3){
			//灰色停止
			return '<font style="color:gray">'+statusName+'(项目已超时'+days+'天,项目已失效)'+'</font>';
		}else if(days<=-5){
			//正常绿色
			return '<font style="color:green">'+statusName+'</font>';
		}
		
	}
	
	//修改 
	function editPrj(id){
		window.location.href="projectEdit.jsp?id="+id;
	}
	
	function selectPrj(id) {
		window.location.href="projectEdit.jsp?id="+id+"&status='status'";
	}
	//查看 
	function viewPrj(id,prjType){
		window.location.href="step.jsp?prjId="+id;
	}
	
	//查看修改的历史记录 
	function selectUpdateRecord(id) {
		showModalFollowRight("projectRecordModen");
		updatePrjRecord(id);
	}
	
	//右侧显示modal
	function showModalFollowRight(modal){
		var modalObj = getJqueryObj(modal);
		
		modalObj.modal();
		setModelFollowRight(modalObj,"600px");
		
	}
	//终止项目
	function stopPrj(id,prjName) {
		Otod.Msg.confirm('确定要终止此项目【'+prjName+'】?',"终止项目", function(){
			 Otod.ajax({
					url:"${ctx}/pm/project/stopPrj.do?id=" + id,
				    type: "GET",
				    successFn: function(data) {
				    	queryPrj();
				    }
				}); 
		});
	}
	
	//模糊查询数据
	function queryObscurePrj(){
		queryPrj();
	}
	
	
	function baseQuery(){
		var prjTableColums = [//定义列
		                      {
		          				"mData":"uuid",
		          				"sClass": "center",
		          				"bSortable": false,
		          				"mRender" : function(data, type, row) {
		          					//html 开始
		          					var html = '<div class="action-buttons">';
		          					// 修改项目配置信息，
		          					var updateHtml = '<a  href="javascript:editPrj(\''+data+'\')" title="修改项目配置信息"><i class="icon-edit bigger-130"></i></a><span class="vbar"></span>';
		          					// 查看项目配置信息，查看项目修改记录，查看阶段任务信息
		          					var viewHtml = '<a href="javascript:selectUpdateRecord(\''+data+'\')" title="查看修改记录"><i class="icon-folder-open bigger-130"></i></a><a href="javascript:selectPrj(\''+data+'\')" title="查看项目信息"><i class="icon-eye-open bigger-130"></i></a><a href="javascript:viewPrj(\''+data+'\')" title="查看阶段任务信息"><i class="icon-tasks bigger-130"></i></a><span class="vbar"></span>';
		          					// 删除项目
		          					var deleteHtml = '<a class="red" id="delProject" title="删除项目" href="javascript:del(\''+data+'\',\''+row.prjName+'\')"><i class="icon-trash bigger-130"></i></a><span class="vbar"></span>';
		          					// 终止项目
		          					var stopHtml = '<a class="red"  title="终止项目" href="javascript:stopPrj(\''+data+'\',\''+row.prjName+'\')"><i class="icon-ban-circle bigger-130"></i></a><span class="vbar"></span>';
		          					//html结束
		          					var endHtml = '</div>';
		          					if(row.roleNo=='30100002'){//项目负责人
		          						if(row.status == '30090001'){//项目初始状态（准备中）
		          							return html+updateHtml+viewHtml+deleteHtml+endHtml;
		          						}else if(row.status =='30090002'){//进行中项目
		          							return html+viewHtml+stopHtml+endHtml;
		          						}else{
		          							return html+viewHtml+endHtml;
		          						}
		          					}else if(row.roleNo == '30100007'){//项目管理员
		          						if(row.status !='30090001' && row.status!='30090004'){
		          							return html+updateHtml+viewHtml+deleteHtml+endHtml;
		          						}else{
		          							return html+viewHtml+endHtml;
		          						}
		          					}else{//其他项目角色
		          						return html+viewHtml+endHtml;
		          					}
		          				}
		                      },
		                      {
		                    	  "mData":"prjName",
		                    	  "bSortable": false,
		                    	  "sClass": "center"
		                      },
		                      {
		                    	  "mData": "prjType",
		                    	  "bSortable": false,
		                    	  "sClass": "center"
		                      },
		                      {
		                    	  "mData":"prjLvl",
		                    	  "bSortable": false,
		                    	  "sClass": "center"
		                      },
		                      {
		                    	  "mData":"startDate",
		                    	  "bSortable": false,
		                    	  "mData": function(data, type, row) {
		          						return DateUtil.dateFormat(data.startDate);
		          					},
		          				  "sClass": "center"
		                      },
		                      {
		                    	  "mData":"endDate",
		                    	  "bSortable": false,
		                    	  "mData": function(data, type, row) {
		          						return DateUtil.dateFormat(data.endDate);
		          				  },
		          				  "sClass": "center"
		                      },
		                      {
		                    	  "mData": "projectSize",
		                    	  "bSortable": false,
		                    	  "sClass": "center"
		                      },
		                      {
		                    	  "mData":"custNo",
		                    	  "bSortable": false,
		                    	  "sClass": "center"
		                      },
		                      {
		                    	  "mData": "statusName",
		                    	  "bSortable": false,
		                    	  "sClass": "center",
		                    	  "mData": function(data, type, row) {
			                    		if(data.status =='30090002'){
			                    			
				          					return checkDate(data.statusName,data.endDate);
			                    		}else{
			                    			return data.statusName;
			                    		}
		                    	  }
		                      },
		                      {
		                    	  "mData":"managerName",
		                    	  "bSortable": false,
			          			  "sClass": "center"
			          		  },
		                      {
			          			  "mData":"trainsRoleNo",
			          			  "bSortable": false,
			          			  "sClass": "center"
			          		  }
		              ];
		          	
		              //初始化dataTable
		          	datatable = $('#prjTable').dataTable( {
		              	'sAjaxSource': '${ctx}/pm/project/queryPrj.do',	//请求数据源 
		              	"fnServerData": function(sSource, aoData, fnCallback,oSettings){
		            		$.extend(aoData,$('#prj_name').serializeArray());
		            		$.ajax({
		        	    		dataType: 'json',
		        	    		url : sSource,
		        	    		data: aoData,
		        	    		success: fnCallback
		            		});		
		              	},
		          		'bServerSide':true,							//是否启动服务器端数据导入
		          		"bLengthChange" : false,
		          		"bInfo" : true,
		          		"bPaginate" : true,
	                  	'bFilter': false,                       	//是否使用内置的过滤功能。
	                  	'aoColumns': prjTableColums,
	                 	"sDom": '<"toolbar">frtip', 
	                   	"oLanguage": oLanguage
		          	});             
	}
	
	$(document).ready(function() {
		
		baseQuery();
		selectUpdatePrjRecord();
		if(GOBAL_CUST_ROLENO=='ProjectAdministrator'){//项目管理员
			$("#addBtn").css("display","none");
		}
		
		
	});
	</script>
<div class="row row-default border-ra2">
	<div class="col-sm-12">
		<div class="row row-tt">
			<div class="col-sm-4">
				<h3 class="header header-default">
					项目列表
				</h3>
			</div>
			<div class="col-sm-5">		
				<!-- <form class="form-horizontal" role="form" name="prjQuery" id="prjQueryForm" action="" method="get">
					<div class="col-sm-5" >
						<label for="q_prjName" class="col-sm-5 control-label">项目名称</label>
						<div class="col-sm-6">
							<input type="text" class="form-control input-sm" id="prj_name" name="prj_name" placeholder="项目名称">
						</div>
					</div>
					<div class="col-sm-7 search-btns">
					    <button type="button" class="btn btn-xs btn-info" onclick="queryObscurePrj();"><i class="icon-search"></i>查询</button>
						<button class="btn btn-xs btn-default" type="reset"><i class="icon-undo"></i>重置</button>
					</div>
				</form> -->
				<form class="form-horizontal" role="form" name="prjQuery" id="prjQueryForm" action="" method="get">
					<div class="input-group">
						<input type="text" class="form-control" id="prj_name" name="prj_name" placeholder="项目名称">
						<span class="input-group-btn">
							<button type="button" class="btn btn-sm btn-info" onclick="queryObscurePrj();"><i class="icon-search"></i>查询</button>
							<button class="btn btn-sm btn-default" type="reset"><i class="icon-undo"></i>重置</button>
						</span>
					</div>
				</form>
			</div>
			<div class="col-sm-3" >
				<a href = "${ctx}/jsp/pm/prj/projectEdit.jsp" ><button id="addBtn" class="btn-ace pull-right" type="button" ><i class="icon-plus"></i> 新增项目</button></a>
			</div>	
		</div>
			
		<div class="row row-content">
			<div class="col-xs-12">
				<div class="table-responsive">
					<table id="prjTable" class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th width="12%"></th>
								<th width="13%">项目名称</th>
								<th width="8%">项目类型</th>
								<th width="4%">项目级别</th>
								<th width="9%">开始时间</th>
								<th width="9%">结束时间</th>
								<th width="9%">项目规模</th>
								<th width="13%">客户名称</th>
								<th width="9%">项目状态</th>
								<th width="9%">项目负责人</th>
								<th >在项目中的角色</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
				</div>
			</div>
		</div>					
	</div>
	<!-- 历史记录页面 -->
	<jsp:include page="projectRecord.jsp"></jsp:include>
</div>
</body>
